IF OBJECT_ID('ssf.job_run_duration_ss') IS NOT NULL
	DROP FUNCTION ssf.job_run_duration_ss
GO

CREATE FUNCTION ssf.job_run_duration_ss (
	@run_duration INT
)
RETURNS INT
AS
BEGIN
/*
<object_header>

<object_summary>
	<purpose><![CDATA[
SQL Agent records job and step run duration in sysjobhistory as an integer (HHHHHHMISS).
Given a run duration, return the duration length in seconds.
	]]></purpose>
</object_summary>

</object_header>
*/

	RETURN (
		(@run_duration % 100)
		+ (@run_duration /100 % 100 * 60)
		+ (@run_duration / 10000 % 1000000 * 60 * 60)
	)
END
GO
